﻿//++
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// Module Name:
//
//  JoinNowVoiceReminder.cs
//    
// Abstract:
//
//  Workflow application for controlling the callflow of a
//  reminder for an autojoin meeting.
//  
//--

using System;
using System.Diagnostics;
using System.Workflow.Activities;
using Microsoft.EnhancedReminders.Dispatcher.Workflow;
using Microsoft.OfficeCommunicationsServer.Applications.Common;
using Microsoft.Rtc.Workflow.Activities;

namespace Microsoft.EnhancedReminders.Dispatcher.Workflow
{
    /// <summary>
    /// SequentialWorkflow for controlling the callflow for a meeting reminder.
    /// </summary>
    public sealed partial class JoinNowVoiceReminder: SequentialWorkflowActivity
    {
        private CalendarNotificationItem _message;
        private NotificationResult _result;

        /// <summary>
        /// ctor.
        /// </summary>
        public JoinNowVoiceReminder()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Get or set the NotificationItem to be delivered. This is intended
        /// to be used as an input parameter.
        /// </summary>
        public CalendarNotificationItem Message
        {
            get
            {
                return _message;
            }
            set
            {
                _message = value;
                JoinNowActivity.Notification = value;

                getPin.Notification = value;
                _result = new NotificationResult(_message, NotificationResultStatus.Error,
                    NotificationChannelType.None);
            }
        }

        /// <summary>
        /// Get or set the NotificationResult from the attempt to deliver
        /// the notification item. This is intended to be accessed as a
        /// return value.
        /// </summary>
        public NotificationResult MessageResult
        {
            get
            {
                return _result;
            }
        }

        /// <summary>
        /// This should be called after we've verified the user's PIN. Verification
        /// of a PIN means that this notification was successful.
        /// </summary>
        private void SetNotificationResult(object sender, EventArgs e)
        {
            Logger.WriteTraceInformation(Message.Context, "Workflow: User has entered a valid PIN.");
            _result.Status = NotificationResultStatus.Success;
        }

        /// <summary>
        /// Called when the conference is joined.
        /// </summary>
        private void JoiningConferenceTurnStarting(object sender, SpeechTurnStartingEventArgs e)
        {
            Logger.WriteTraceInformation(Message.Context, "Workflow: Now joining the conference.");

            Uri basePath = new Uri(this.GetType().Assembly.Location);
            MeetingNotificationItem meeting = Message as MeetingNotificationItem;
            Debug.Assert(meeting != null, "meeting != null");
            

            joiningConference.MainPrompt.AppendAudio(new Uri(basePath, new Uri(PromptAudio.JoinNow_MainPrompt_1, UriKind.Relative))); // "OK.  This meeting was organized by"
            joiningConference.MainPrompt.AppendText(meeting.NotificationOriginator);
            joiningConference.MainPrompt.AppendAudio(new Uri(basePath, new Uri(PromptAudio.JoinNow_MainPrompt_2, UriKind.Relative))); // "Subject"
            joiningConference.MainPrompt.AppendText(Message.Message);
            joiningConference.MainPrompt.AppendAudio(new Uri(basePath, new Uri(PromptAudio.JoinNow_MainPrompt_3, UriKind.Relative))); // "Hang on while I join you to the meeting…"
        }
    }
}
